﻿using System;
using System.Collections;

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            //查找集合中是否含有 abc 元素
            ArrayList list = new ArrayList() { "aaa", "bbb", "abc", };
            int index = list.IndexOf("abc");
            if (index != -1)
            {
                Console.WriteLine("该集合含有abc");
            }
            else
            {
                Console.WriteLine("该集合不含abc");
            }
            Console.WriteLine();

            //将集合中元素下标是偶数的元素添加到另一个集合中
            ArrayList list1 = new ArrayList() { "html", "java", "sql", "c#" };
            ArrayList newList1 = new ArrayList();
            Console.Write("下标是偶数的元素有：");
            for (int i = 0; i < list.Count; i = i + 2)
            {
                newList1.Add(list1[i]);
            }
            foreach (var v in newList1)
            {
                Console.Write(v);
            }
            Console.WriteLine();
            Console.WriteLine();


            //在集合中第一个元素的后面插入元素
            ArrayList arr1 = new ArrayList() {"食堂","的洋葱炒蛋",};
            ArrayList arr2 = new ArrayList() { "不想吃" };
            arr2.InsertRange(1, arr1);
            foreach (var n in arr2)
            {
                Console.WriteLine(n);
            }
            Console.WriteLine();


            //将集合中的元素使用 Sort 方法排序后输出
            ArrayList arr3 = new ArrayList() {1,2,3,4};
            arr3.Sort();
            foreach(var x in arr3)
            {
                Console.Write(x);
            }

            

        }
    }
}
